﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.ComponentModel;
using System.Windows.Forms;
using NetJsWire.JsonRpcHandler;
using NetJsWire.JsonRpcHandler.Attributes;
using NetJsWire.JsonRpcHandler.Util;
using NetJsWire.Widgets.Config;

namespace NetJsWire.Widgets.Ui.ToolBar
{
    [Renderer( typeof( Renderers.Form.ComboBox ) )]
    public partial class ComboBox : ToolStripComboBox, IWidget, IComboBox
    {
        private readonly IRenderer _renderer;
        private IConfigOptions _configOptions;
        private bool _sendUpdates = true;

        public ComboBox()
        {
            InitializeComponent();

            _renderer = Helper.GetRenderer( this );
        }

        public ComboBox( IContainer container )
        {
            container.Add( this );

            InitializeComponent();

            _renderer = Helper.GetRenderer( this );
        }

        #region IComboBox Members

        [DefaultValue( true )]
        public bool SendUpdates
        {
            get { return _sendUpdates; }
            set { _sendUpdates = value; }
        }

        public int TabIndex
        {
            get; set;
        }

        #endregion

        #region Implementation of IWidget

        ///<summary>
        ///  The renderer is the responsible for representing the object in the client side.
        ///</summary>
        public IRenderer Renderer
        {
            get { return _renderer; }
        }

        /// <summary>
        ///   Add a client event to the Widget in the form of: Windget.on('name', function);
        /// </summary>
        /// <param name = "name">The event name.</param>
        /// <param name = "function">A function name or inline code to execute.</param>
        public void On( string name, string function )
        {
            Renderer.AddClientEvent( name, function );
        }

        /// <summary>
        ///   Adds a CSS class to the component's underlying element.
        /// </summary>
        /// <param name = "cls">The CSS class name to add.</param>
        public void AddClass( string cls )
        {
            throw new NotImplementedException();
        }

        /// <summary>
        ///   Removes a CSS class from the component's underlying element.
        /// </summary>
        /// <param name = "cls">The CSS class name to remove.</param>
        public void RemoveClass( string cls )
        {
            throw new NotImplementedException();
        }

        public bool GenerateClientMember
        {
            get; set;
        }

        public IConfigOptions ConfigOptions
        {
            get { return _configOptions ?? ( _configOptions = new BoxComponentConfigOptions( this ) ); }
        }

        #endregion
    }
}
